﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jzy.Workflow.Form;
using Jzy.Workflow.Task;
using Jzy.Core.Common.Web;
using Frame.Lib.Utilities;
using Frame.Lib.Common;


namespace Jzy.Web.WorkFlow.Fore
{
    public partial class DraftList :PageList
    {
        private FlowTaskBO _task = new FlowTaskBO();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindView();
            }
            AddAttr();
            base.InitSelectID(hidSelectIDs);
        }

        private void AddAttr()
        {
            JSUtil.DelConfirm(btnDelete, "表单");
            JSUtil.ClickBtn(lnkDelete, btnDelete);
        }

        protected FlowFormInfo GetForm(object form)
        {
            return (FlowFormInfo)form;
        }


        private void BindView()
        {
            base.InitLV(lv, lvHeader);
            lv.EnableViewState = true;
            IEnumerable<FlowTaskInfo> tasks = _task.GetDraftList(AppSession.UserID);
            lv.DataSource = tasks;
            lv.DataKeyNames = new string[] { "ID"};
            lv.DataBind();
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (base.strSelectIDs == "")
            {
                return;
            }
            List<string> taskIDs = StrUtil.SplitToStr(strSelectIDs);
            _task.DeleteDraft(taskIDs);
            BindView();
        }

        protected void lv_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            if (e.CommandName == "Del")
            {
                string formID = e.CommandArgument.ToString();
                FlowFormBO form = new FlowFormBO();
                form.Delete(formID);
                BindView();
            }
        }

       
    }
}
